package com.thitech.sif.utils.log;

import com.thitech.sif.AbsOutput;
import com.thitech.sif.Executor;
import com.thitech.sif.interceptor.InterceptorHandler;

/**
 * log message builder
 * @author shisheng.lian
 * @date 2014-08-10
 */
public class LogBuilder {
	private static final String SPLIT = "::::";
	private static final String ENTER = "\n";
	
	public static String getLogMsg(Executor executor, String logMsg) {
		StringBuilder sb = new StringBuilder();
		if (null != executor) {
			sb.append(executor.toString());
			sb.append(ENTER);
		}
		sb.append(logMsg);
		return sb.toString();
	}
	
	public static String interceptorAfterDebug(InterceptorHandler interceptor, Executor executor, AbsOutput output) {
		StringBuilder sb = new StringBuilder();
		String interceptorClassName = interceptor.getClass().getName() + ".after";
		sb.append(ENTER);
		sb.append(interceptorClassName);
		sb.append(ENTER);
		sb.append(executor.toString());
		sb.append(SPLIT);
		sb.append(output.toString());
		sb.append(ENTER);
		return sb.toString();
	}
	
	public static String interceptorBeforeDebug(InterceptorHandler interceptor, Executor executor) {
		StringBuilder sb = new StringBuilder();
		String interceptorClassName = interceptor.getClass().getName() + ".before";
		sb.append(ENTER);
		sb.append(interceptorClassName);
		sb.append(ENTER);
		sb.append(executor.toString());
		sb.append(ENTER);
		return sb.toString();
	}
}
